<template>
	<view class="bg-[#fff] contentbox">
		<view class="">
			<navbar title="商品详情"></navbar>
		</view>
		<view class="h-[480rpx] w-[100%]">
			<u-swiper height="480rpx" :list="bullsdetals.goodsInfo.goodsImages" @change="e => currentNum = e.current"
				:autoplay="false" imgMode="aspectFit" indicatorMode="line" circular>
				<template #indicator>
					<view class="indicator-num">
						<text
							class="indicator-num__text">{{ currentNum + 1 }}/{{ bullsdetals.goodsInfo.goodsImages.length }}</text>
					</view>
				</template>
			</u-swiper>
		</view>
		<view class="">
			<view class="title px-[20rpx] w-[100%] line-clamp-1 break-words">
				{{bullsdetals.goodsInfo.goodsName}}
			</view>
			<view class="mt-[10rpx]">
				<view class="">
					<view class="centerheight justify-between  pb-[24rpx]">
						<view class="pl-[20rpx]">
							<view class="centerheight">
								<view class="mr-[10rpx]">
									<image src="@/static/homeimg/time.svg" class="w-[26rpx] h-[26rpx]" mode=""></image>
								</view>
								<view class="text-[26rpx] text-[#393939]">
									配送约 {{delivertime}} 分钟 <text class="mx-[20rpx]">I</text> 月售
									{{getsanum(bullsdetals.goodsInfo.monthSales)}}
								</view>
							</view>
							<view class="flex items-end mt-[10rpx]">
								<view class="text-[#FB2A2A] text-[30rpx] mr-[20rpx]">
									￥<text
										class="text-[45rpx] leading-[45rpx]">{{bullsdetals.goodsInfo.goodsPrice}}</text>
								</view>
								<view class="text-[26rpx] text-[#6C6C6C] leading-[40rpx] mr-[20rpx]" v-if="bullsdetals.goodsInfo?.specType==1">
									打包费 ￥{{bullsdetals.goodsInfo.packagePrice}}/份
								</view>
								<view class="text-[26rpx] text-[#6C6C6C] leading-[40rpx]" v-if="bullsdetals.goodsInfo?.specType==1">{{bullsdetals.goodsInfo?.weight}}{{unitslist[bullsdetals.goodsInfo?.unit-1]?.label}}</view>
							</view>
						</view>
						<view class="flex  relative top-[14rpx] right-[20rpx] items-end" v-if="store.isaddcart==1">
							<view class="" v-if="bullsdetals.goodsInfo.specType==1">
								<view v-if="ishavue>0">
									<view class="flex"
										v-if="bullsdetals.goodsInfo.stockNum!==0 && bullsdetals.goodsInfo.goodsStatus!==2">
										<view class="" @click="jaddshop(ishavue)" v-show="ishavue>0">
											<view class="jaddcar">
												<u-icon name="minus" bold color="#FE861C" top="" size="10"></u-icon>
											</view>
										</view>
										<view class="numbershop" v-if="ishavue>0">
											{{ishavue}}
										</view>
										<view class="addcars"
											v-if="headtals.distance>headtals.storeConfig.deliveryRatio">
											<view class="">
												<u-icon name="plus" bold color="#fff" size="12"></u-icon>
											</view>
										</view>
										<view class="addcar" @click="addshop(bullsdetals.goodsInfo)" v-else>
											<view class="">
												<u-icon name="plus" bold color="#fff" size="12"></u-icon>
											</view>
										</view>
									</view>
								</view>
								<view class="" v-else>
									<view class="btnBox flex items-center justify-center  mr-[20rpx]" @click="addshop">
										<u-icon name="plus" size="24rpx" top="4rpx" color="#fff"></u-icon>
										<view class="ml-[4rpx] flex items-center">
											加入购物车
										</view>
									</view>
								</view>
							</view>
							<view class="relative" v-else @click="addshop">
								<view class="addcarsa"
									v-if="bullsdetals.goodsInfo.stockNum!==0 && bullsdetals.goodsInfo.goodsStatus!==2">
									选规格
								</view>
								<view class="addcarsas" v-else>
									选规格
								</view>
								<view class="" style="position: absolute;top: -12rpx; right: -15rpx;">
									<up-badge bg-color="#F12A2A" v-if="ishavue > 0" type="error" max="99"
										:value="ishavue"></up-badge>
								</view>
							</view>
						</view>
					</view>
					<view class="oneboder">
					</view>
				</view>
			</view>
			<view class="px-[20rpx]">
				<view class="py-[20rpx] detalstitle">
					商品详情
				</view>
				<view class="detalcontent" v-if="bullsdetals.goodsInfo.content!==''">
					{{bullsdetals.goodsInfo.content}}
				</view>
				<view v-else class="flex justify-center items-center h-[400rpx] text-[28rpx] text-[#999]">
					暂无描述
				</view>
			</view>
		</view>
		<WuSkus v-model="skuShow" class="popupShows" :data="skus" :themeColor="[254, 134, 28]" btnConfirmText="加入购物车"
			:defaultCover="imgdang" :specType="specTypedang" :prices='pricedang' :defaultNum="defaultNum"
			@numChange="numChange" :batchsprice="batchingId" :stockNum="dangstockNum" notSelectSku="请选择完整的商品信息"
			@skuChange="skuChange" @confirm="confirm">
			<template v-slot:batching>
				<view class="mt-[50rpx] mb-[10rpx]" v-if="bachlist.length>0">
					<view class="text-[30rpx]">配料</view>
					<view class="flex flex-wrap">
						<view class="flex" v-for="(item,index) in bachlist" :key="index"
							:class="havebatch(item)?'boxbachtactive':'boxbacht'" @click="choseback(item)">
							<view class="rightbodr">
								{{item.batchingName}}
							</view>
							<view class="lingsd flex items-center">
								￥{{item.price}}
							</view>
						</view>
					</view>
				</view>
			</template>
		</WuSkus>
		<view
			class="fixed bottom-0 w-[100%] h-[140rpx] bg-[#000] opacity-[0.6] px-[50rpx] justify-between flex items-center text-[#fff]"
			v-if="store.isaddcart==0">
			<view class="text-[40rpx] text-center w-[100%]">
				{{headtals.businessStatus==1?'无法配送到当前位置':"门店休息中"}}
			</view>
		</view>
		<view class="button" style="z-index: 99999;" v-if="store.isaddcart==1">
			<view class="flex btinone">
				<view class="relative " @click="opencart"
					v-if="cartDetails.data < headtals.storeConfig.startDeliveryPrice">
					<image class="imghui" src="../../static/homeimg/huiwm.png" mode=""></image>
					<view class="absolute top-0 right-0 " v-if="cartDetails.list2.length>0">
						<up-badge numberType="overflow" :type="type" max="99" :value="shopnum"></up-badge>
					</view>
				</view>
				<view @click="opencart" class="relative"
					v-if="cartDetails.data >= headtals.storeConfig.startDeliveryPrice">
					<image class="imghui" src="../../static/homeimg/huangwm.png" mode=""></image>
					<view class="absolute top-0 right-0 " v-if="cartDetails.list2.length>0">
						<up-badge numberType="overflow" :type="type" max="99" :value="shopnum"></up-badge>
					</view>
				</view>
				<view class="money">
					<view class="nummoney text-[28rpx] leading-[38rpx]">
						￥<text class="text-[38rpx]">{{cartDetails.data.toFixed(2)}}</text>
					</view>
					<view class="relative bottom-[4rpx]">
						预估加配送费￥{{headtals.storeConfig.deliveryPrice}}元

					</view>
				</view>
			</view>
			<view @click="gobill(cartDetails.data >= headtals.storeConfig.startDeliveryPrice)" class="smallbuton"
				:class="cartDetails.data >= headtals.storeConfig.startDeliveryPrice ? 'smallbuton2':''">
				<view v-if="cartDetails.data >= headtals.storeConfig.startDeliveryPrice">
					去结算
				</view>
				<view class="" v-else>
					￥{{headtals.storeConfig.startDeliveryPrice}} 起送
				</view>
			</view>
		</view>
		<u-popup class="popupShow" :safeAreaInsetBottom="true" :closeOnClickOverlay="true" :show="showcart"
			@close="showcart=false" @open="cartOpen" height="600rpx" :round="20">
			<view class="p-[30rpx]  ">
				<!-- 头部 -->
				<view class="flex justify-between">
					<view class="flex">
						<view class="">
							已选商品
						</view>
						<view class="text-[24rpx] flex items-end">
							(打包费￥ <text class="text-[red]">{{pagepricenum}}</text>)
						</view>
					</view>
					<view @click="delcart()" class="">
						清空购物车
					</view>
				</view>
				<u-divider></u-divider>
				<!-- 购物车列表 -->
				<view class="">
					<scroll-view style="height: 500rpx;" scroll-y="true">
						<view class="" v-for="(item,index) in cartDetails.list2" :key="index">
							<view class="flex">
								<view class="">
									<image class="w-[100rpx] h-[100rpx] rounded-[20rpx]" :src="item.goodsImages[0]">
									</image>
								</view>
								<view class="pl-[6rpx] w-[100%]">
									<view class="flex">
										<view class="ml-[20rpx] text-[28rpx] leading-[28rpx]">
											<up-text :text="item.goodsName"></up-text>
										</view>
									</view>
									<view class="pl-[22rpx] salesNum felx justify-between mounys mt-[8rpx] w-[100%]">
										<view>
											<view class="flex flex-nowrap mr-[20rpx]"
												v-if="item.batchingIds!==null || item.weight || item.goodsStock?.suk">
												<view class="text-[24rpx] text-[#999999]">
													<text v-if="item.weight">{{item.weight}}、</text> <text
														v-if="item.batchingIds!==null">
														{{ item.batchingIds[0].batchingName}}</text>
													<text v-if="item.goodsStock?.suk" class="ml-[10rpx]">
														{{item.goodsStock?.suk}}</text>
												</view>
											</view>
										</view>
									</view>
									<view class="flex justify-between mt-[10rpx] ml-[20rpx]">
										<view class="text-[red]">
											<text class="text-[24rpx]">￥</text>{{item.subtotalPrice}}
										</view>
										<view class="flex items-end">
											<view class="" v-show="item.num>0" @click="cartjian(item,index)">
												<view class="jaddcar">
													<u-icon name="minus" color="#FE861C" size="10"></u-icon>
												</view>
											</view>
											<view class="numbershop" v-if="item.num>0">
												{{item.num}}
											</view>
											<view class="addcar" @click="cartadd(item)">
												<view class="">
													<u-icon name="plus" color="#fff" size="12"></u-icon>
												</view>
											</view>
										</view>
									</view>
								</view>
							</view>
							<u-divider lineColor="#efefef"></u-divider>
						</view>
					</scroll-view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script setup>
	import navbar from "@/components/navgetbar/navindex.vue"
	import WuSkus from "@/components/sku/sku.vue"
	import {
		isEqualArray
	} from "@pureadmin/utils"
	// import WuSkus from "@/components/wu-sku/components/wu-sku/wu-sku.vue"
	import {
		useStore
	} from '@/stores/user.js'
	import {
		useAppStore
	} from "@/stores/app.js"
	const store = useStore();
	import {
		ref,
		reactive
	} from "vue"
	import {
		storebusiness,
		gooddetals,
		storenamedetal,
		storecartdetals,
		decreaseGoods,
		storecart,
		deleteGoods
	} from "@/api/home.js"
	const bullsdetals = ref({
		goodsInfo: {
			goodsImages: [],
			monthSales: 0
		}
	})
	import {
		onLoad,
		onShow
	} from "@dcloudio/uni-app"
	const headtals = reactive({
		storeConfig: {
			startDeliveryPrice: 0,
			deliveryPrice: 0
		}
	})
	const isaddcart = ref(0)
	onShow(() => {
		isaddcart.value = store.isaddcart
	})
	const currentNum = ref(0)
	//购物车详情
	let cartDetails = reactive({
		data: 0,
		list: {},
		list2: {}
	})
	const ishavue = ref(0)
	const shopnum = ref(0)
	const pagepricenum = ref(0)
	const cardetaslist = (id) => {
		storecartdetals({
			storeId: storeId.value
		}).then(res => {
			if (res.code == 200 && res.result.cart !== null) {
				cartDetails.data = res.result.cart.totalAmount
				cartDetails.list = res.result.cart
				cartDetails.list2 = res.result.cart.data
				shopnum.value = 0
				pagepricenum.value = 0
				res.result.cart.data.forEach(item => {
					shopnum.value += item.num
					pagepricenum.value += item.num * item.packagePrice
				})
				ishavue.value = 0
				res.result.cart.data.forEach(item => {
					if (item.id == shopids.value && item.specType == 2) {
						ishavue.value += item.num
						bullsdetals.value.goodsInfo.num = ishavue.value
					} else if (item.id == shopids.value && item.specType == 1) {
						ishavue.value = item.num
						bullsdetals.value.goodsInfo.num = ishavue.value
					}
				})
			} else {
				cartDetails.data = 0
				ishavue.value = 0
				cartDetails.list2 = []
				cartDetails.list.data = []
				// uni.hideLoading();
			}
		}).catch(err => {
			console.log(err)
		})
	}
	//清空购物车
	let delcart = () => {
		deleteGoods({
			storeId: storeId.value
		}).then(res => {
			if (res.code == 200) {
				ishavue.value = 0
				bullsdetals.value.goodsInfo.num = 0
				uni.showToast({
					title: "购物车已清空",
					icon: 'none'
				})
				cardetaslist()
				showcart.value = false
			}
		}).catch(err => {
			console.log("异常", err)
		})
	}
	const delivertime = ref(0)
	const storeId = ref(0)
	const shopids = ref(0)
	const unitslist = ref([{
		label: '克(g)',
		id: 1
	}, {
		label: '千克(kg)',
		id: 2
	}, {
		label: '毫升(ml)',
		id: 3
	}, {
		label: '升(L)',
		id: 4
	}, {
		label: '斤',
		id: 5
	}, {
		label: '两',
		id: 6
	}])
	onLoad((e) => {
		shopids.value = e.id
		delivertime.value = e.delivertime
		storeId.value = e.storeId
		storebusiness({
			goodsId: e.id,
			storeId: e.storeId
		}).then(res => {
			if (res.code == 200) {
				bullsdetals.value = res.result
			}
		})
		storenamedetal({
			storeId: e.storeId
		}).then(res => {
			if (res.code == 200) {
				Object.assign(headtals, res.result)
			}
		})
		cardetaslist(e.storeId)
	})
	//打开购物车
	let showcart = ref(false)
	let opencart = () => {
		if (cartDetails.list2.length > 0) {
			showcart.value = true
		}
	}
	//弹窗增加购物车
	let cartadd = (item) => {
		item.num++
		item.storeId = headtals.id
		storecart({
			storeId: headtals.id,
			goods: cartDetails.list2
		}).then(res => {
			if (res.code == 200) {
				cardetaslist()
			}
		})
	}
	// 购物车的减
	let cartjian = (item, indexs) => {
		if (item.num > 0) {
			item.num--
		}
		if (item.num == 0) {
			cartDetails.list2.forEach((items, index) => {
				if (item.id == items.id && indexs == index) {
					cartDetails.list2.splice(index, 1)
				}
			})
		}
		switch (true) {
			case cartDetails.list2.length < 1:
				delcart()
				return;
		}
		storecart({
			storeId: headtals.id,
			goods: cartDetails.list2
		}).then(res => {
			if (res.code == 200) {
				cardetaslist()
			}
		})
	}
	//去结算
	let gobill = (e) => {
		if (e) {
			uni.navigateTo({
				url: '/page_order/submitanorder/submitanorder?id=' + headtals.id + '&storenName=' + headtals
					.storeName +
					'&deliveryType=' + headtals.storeConfig.deliveryType + '&deliveryPrice=' + headtals
					.storeConfig.deliveryPrice
			})
		}
	}
	//但规格
	const addshopdan = (item) => {
		if (item.num == undefined || item.num == NaN) {
			item.num = 1
		} else {
			item.num++
		}
		gooddetals({
			goodsId: item.id,
			storeId: storeId.value
		}).then(res => {
			if (res.code == 200) {
				const goodsInfo = res.result.goodsInfo
				let data = {
					storeId: headtals.id,
					goods: [{
						num: item.num,
						id: goodsInfo.id,
						cateId: goodsInfo.cateId,
						goodsCateId: goodsInfo.goodsCateId,
						specType: goodsInfo.specType,
						batchingIds: null,
						storeId: headtals.id,
						goodsName: goodsInfo.goodsName,
						packagePrice: goodsInfo.packagePrice,
						content: goodsInfo.content,
						goodsPrice: item.goodsPrice,
						goodsImages: goodsInfo.goodsImages,
						weight: goodsInfo.weight
					}]
				}
				if (cartDetails.list2.length < 1) {
					storecart(data).then(res => {
						if (res.code == 200) {
							cardetaslist()
						}
					})
				} else {
					cartDetails.list2.forEach((item, index) => {
						if (item.id == goodsInfo.id) {
							cartDetails.list2.splice(index, 1)
						}
					})
					cartDetails.list2.push(data.goods[0])
					storecart({
						storeId: headtals.id,
						goods: cartDetails.list2
					}).then(res => {
						if (res.code == 200) {
							cardetaslist()
						} else {
							uni.showToast({
								icon: 'none',
								title: res.msg
							})
						}
					})
				}

			}
		})
	}
	//多规格
	const skuShow = ref(false)
	let skus = ref([{
		packagePrice: "34",
		id: 2,
		price: 100,
		stock: 200,
		// skuAttr: {大小: "大", 颜色: "红色"},
		sku_attrs: {
			'大小': "大",
			'颜色': "色"
		},
	}, ])
	//减少单规格商品
	const jaddshop = (num) => {
		bullsdetals.value.goodsInfo.num = num
		let item = bullsdetals.value.goodsInfo
		if (item.num > 0) {
			item.num--
		}
		switch (true) {
			case cartDetails.list2.length == 1:
				cartDetails.list2.forEach((items, index) => {
					if (item.id == items.id) {
						items.num--
						if (items.num == 0) {
							delcart()
						} else {
							storecart({
								storeId: storeId.value,
								goods: cartDetails.list2
							}).then(res => {
								if (res.code == 200) {
									cardetaslist()
								}
							})
						}
					}
				})
				return;
			case cartDetails.list2.length !== 1:
				for (let i = 0; i <= cartDetails.list2.length; i++) {
					if (item.id == cartDetails.list2[i].id && item.num == 0) {
						cartDetails.list2.splice(i, 1)
						storecart({
							storeId: storeId.value,
							goods: cartDetails.list2
						}).then(res => {
							if (res.code == 200) {
								cardetaslist()
							}
						})
						return;
					} else if (item.id == cartDetails.list2[i].id && item.num !== 0) {
						cartDetails.list2[i].num--
						storecart({
							storeId: storeId.value,
							goods: cartDetails.list2
						}).then(res => {
							if (res.code == 200) {
								cardetaslist()
							}
						})
						return;

					}
				}

		}
	}
	const addshop = () => {
		if (ishavue.value >= bullsdetals.value.goodsInfo.stockNum) {
			uni.showToast({
				icon: 'none',
				title: '库存不足'
			})
			return;
		}
		//单规格添加
		if (bullsdetals.value.goodsInfo.specType == 1) {
			// 单规格无配料添加
			if (bullsdetals.value.batchings == null || bullsdetals.value.batchings.length < 1) {
				addshopdan(bullsdetals.value.goodsInfo)
			} else {
				select(bullsdetals.value.goodsInfo.specType, bullsdetals.value.goodsInfo.id, bullsdetals.value
					.goodsInfo)
			}

		} else {
			select(bullsdetals.value.goodsInfo.specType, bullsdetals.value.goodsInfo.id, bullsdetals.value.goodsInfo)
		}
	}
	//配料
	const bachlist = ref([])
	const specTypedang = ref(0)
	const pricedang = ref(0)
	const imgdang = ref("")
	const dangstockNum = ref(0)
	const dangweight = ref("")
	const batchingId = ref([])
	//选择配料
	const choseback = (item) => {
		let ishabatching = batchingId.value.filter(items => items.batchingId == item.batchingId)
		if (ishabatching.length !== 0) {
			batchingId.value = batchingId.value.filter(items => items.batchingId !== item.batchingId)
		} else {
			batchingId.value.push({
				batchingId: item.batchingId,
				batchingName: item.batchingName,
				price: item.price,
			})
		}
		batchingId.value = batchingId.value.sort((a, b) => a.batchingId - b.batchingId);
		skuChange(selectsku.value)
	}
	//回显数量
	const defaultNum = ref(0)
	const selectsku = ref({})
	// sku发生改变事件, 选择完整的sku则回返回 否则sku的值为{}
	let skuChange = (sku) => {
		if (cartDetails.list2.length < 1 && bullsdetals.value.goodsInfo.specType == 2) {
			console.log("1111报错1")
			return;
		}
		console.log(cartDetails.list2, "报错")
		defaultNum.value = 0
		if (sku) {
			selectsku.value = sku
		}
		if (cartDetails.list2.some((item) => item.id === itemCount.data.id) && specTypedang.value == 2) {
			for (let i = 0; i < cartDetails.list2.length; i++) {
				if (itemCount.data.id == cartDetails.list2[i]?.id && sku?.id == cartDetails.list2[i].goodsStock.id) {
					if (cartDetails.list2[i]?.batchingIds == null) {
						if (batchingId.value.length < 1) {
							defaultNum.value = cartDetails.list2[i].num
							return;
						} else {
							defaultNum.value = 0
						}
					} else {
						if (isEqualArray(cartDetails.list2[i]?.batchingIds, batchingId.value)) {
							defaultNum.value = cartDetails.list2[i].num
							return;
						} else {
							defaultNum.value = 0
						}
					}
				} else {
					defaultNum.value = 0
				}
			}
		} else if (cartDetails.list2.some((item) => item.id === itemCount.data.id) && specTypedang.value == 1) {
			for (let i = 0; i < cartDetails.list2.length; i++) {
				if (cartDetails.list2[i]?.batchingIds == null && batchingId.value.length < 1 && cartDetails
					.list2[i].id == itemCount.data.id) {
					defaultNum.value = cartDetails.list2[i].num
					return;
				} else if (isEqualArray(cartDetails.list2[i]?.batchingIds, batchingId.value) && cartDetails
					.list2[i].id == itemCount.data.id) {
					defaultNum.value = cartDetails.list2[i].num
					return;
				} else {
					defaultNum.value = 0
					console.log(defaultNum.value, '03')
				}

			}
		} else {
			defaultNum.value = 0
		}

	}
	const numChange = (e) => {
		defaultNum.value = e
	}
	//判断配料是否被选中
	const havebatch = (item) => {
		let ishabatchings = batchingId.value.filter(items => items.batchingId == item.batchingId)
		if (ishabatchings.length > 0) {
			return true
		} else {
			false
		}
	}

	let itemCount = reactive({
		data: []
	})
	//已售数量展示
	const getsanum = (e) => {
		switch (true) {
			case e <= 100:
				return e;
			case e <= 1000:
				return parseInt(e / 100) * 100 + '+';
			case e <= 10000:
				return parseInt(e / 1000) * 1000 + '+';
			case e > 10000:
				return 9999 + '+';
		}
	}
	let select = (item, id, e) => {
		batchingId.value = []
		itemCount.data = e
		skus.value = []
		if (item == 2) {
			gooddetals({
				goodsId: id,
				storeId: storeId.value
			}).then(res => {
				if (res.code == 200) {
					if (res.result.goodsInfo.specType == 2) {
						skus.value = []
						let es = res.result.goodsAttr.length
						res.result.goodsStock.forEach((item, index) => {
							if (es > 1) {
								skus.value.push({
									packagePrice: item.packagePrice,
									id: item.id,
									price: item.price,
									suk: item.suk,
									stock: item.stock,
									weight: item.weight,
									unit:item.unit,
									sku_attrs: {
										[res.result.goodsAttr[0].attrName]: item.skuOne,
										[res.result.goodsAttr[1].attrName]: item.skuTwo
									}
								})
							} else {
								skus.value.push({
									packagePrice: item.packagePrice,
									id: item.id,
									suk: item.suk,
									price: item.price,
									unit:item.unit,
									stock: item.stock,
									weight: item.weight,
									sku_attrs: {
										[res.result.goodsAttr[0].attrName]: item.skuOne
									}
								})
							}

						})
					} else {
						skus.value = []
					}
					bachlist.value = res.result.batchings
					specTypedang.value = res.result.goodsInfo.specType
					dangweight.value = res.result.goodsInfo.weight
					pricedang.value = res.result.goodsInfo.goodsPrice
					dangstockNum.value = res.result.goodsInfo.stockNum
					imgdang.value = res.result.goodsInfo.goodsName
					skuShow.value = true
				}
			})
		} else {
			gooddetals({
				goodsId: id,
				storeId: storeId.value
			}).then(res => {
				if (res.code == 200) {
					skuShow.value = true
					specTypedang.value = res.result.goodsInfo.specType
					pricedang.value = res.result.goodsInfo.goodsPrice
					dangstockNum.value = res.result.goodsInfo.stockNum
					bachlist.value = res.result.batchings
					dangweight.value = res.result.goodsInfo.weight
					imgdang.value = res.result.goodsInfo.goodsName
					if (res.result.goodsInfo.specType == 2) {
						skus.value = []
						let es = res.result.goodsAttr.length
						res.result.goodsStock.forEach((item, index) => {
							if (es > 1) {
								skus.value.push({
									packagePrice: item.packagePrice,
									id: item.id,
									weight: item.weight,
									price: item.price,
									stock: item.stockNum,
									sku_attrs: {
										[res.result.goodsAttr[0].attrName]: item.skuOne,
										[res.result.goodsAttr[1].attrName]: item.skuOne
									}
								})
							} else {
								skus.value.push({
									packagePrice: item.packagePrice,
									id: item.id,
									weight: item.weight,
									price: item.price,
									stock: item.stockNum,
									sku_attrs: {
										[res.result.goodsAttr[0].attrName]: item.skuOne
									}
								})
							}

						})
					}
				}
			})
		}
	}
	// sku确认事件
	let confirm = (e) => {
		if (e.num == 0) {
			switch (true) {
				case cartDetails.list2.length == 1:
					cartDetails.list2.forEach((items, index) => {
						if (itemCount.data.id == items.id) {
							delcart()
						}
					})
					return;
				case cartDetails.list2.length !== 1:
					for (let i = 0; i < cartDetails.list2.length; i++) {
						let arr1 = cartDetails.list2[i].batchingIds == null ? [] : cartDetails.list2[i].batchingIds
						let arr2 = batchingId.value
						if (itemCount.data.id == cartDetails.list2[i].id && isEqualArray(arr1, arr2)) {
							cartDetails.list2.splice(i, 1)
							storecart({
								storeId: storeId.value,
								goods: cartDetails.list2
							}).then(res => {
								if (res.code == 200) {
									cardetaslist()
								}
							})
							return;
						}
					}
			}
		} else {
			//获取商品详情
			gooddetals({
				goodsId: itemCount.data.id,
				storeId: storeId.value
			}).then(res => {
				if (res.code == 200) {
					let bachlists = []
					if (batchingId.value.length > 0) {
						bachlists = batchingId.value
					} else {
						bachlists = null
					}
					const goodsInfo = res.result.goodsInfo
					let data = {
						storeId: headtals.id,
						goods: [{
							num: e.num,
							// skuId: e.sku.id,
							storeId: headtals.id,
							id: goodsInfo.id,
							categoryId: goodsInfo.categoryId,
							goodsCateId: goodsInfo.goodsCateId,
							batchingIds: bachlists,
							specType: goodsInfo.specType,
							goodsName: goodsInfo.goodsName,
							packagePrice: goodsInfo.packagePrice,
							content: goodsInfo.content,
							goodsPrice: specTypedang.value == 2 ? e.sku.price : pricedang.value,
							goodsImages: goodsInfo.goodsImages,
							weight: specTypedang.value == 2 ? e.sku.weight : dangweight.value,
							goodsStock: specTypedang.value == 2 ? {
								id: e.sku.id,
								suk: e.sku.suk,
								weight: specTypedang.value == 2 ? e.sku.weight : dangweight
									.value
							} : {}
						}]
					}
					//判断是否已经添加过同样的商品
					switch (true) {
						case cartDetails.list2.length < 1: //购物车无数据
							storecart(data).then(res => {
								if (res.code == 200) {
									cardetaslist()
								}
							})
							return;
						case cartDetails.list2.length > 0: //购物车有数据
							let isadd = ref(false)
							let filteredArr = cartDetails.list2.filter(function(item) { //过滤商品是否有相同的id
								return item.id === goodsInfo.id;
							});
							if (goodsInfo.specType == 2 && filteredArr.length > 0) { //判断商品相同的商品是否为多规格
								let isalltrue = true
								for (let i = 0; i < cartDetails.list2.length; i++) {
									if (cartDetails.list2[i].batchingIds == null && batchingId.value.length ==
										0 && cartDetails.list2[i].id == goodsInfo.id && e.sku.id == cartDetails
										.list2[i].goodsStock.id) {
										cartDetails.list2[i].num = data.goods[0].num
										storecart({
											storeId: headtals.id,
											goods: cartDetails.list2,
										}).then(res => {
											if (res.code == 200) {
												cardetaslist()
											}
										})
										return;
									} else if (isEqualArray(cartDetails.list2[i].batchingIds, batchingId
											.value) && cartDetails.list2[i].id == goodsInfo.id && e.sku.id ==
										cartDetails.list2[i].goodsStock.id) {
										cartDetails.list2[i].num = data.goods[0].num
										storecart({
											storeId: headtals.id,
											goods: cartDetails.list2,
										}).then(res => {
											if (res.code == 200) {
												cardetaslist()
											}
										})
										return;
									} else if (cartDetails.list2[i].id == goodsInfo.id && !isEqualArray(
											cartDetails.list2[i].batchingIds, batchingId.value) && i ==
										cartDetails.list2.length - 1 && e.sku.id == cartDetails.list2[i]
										.goodsStock.id) {
										cartDetails.list2.push(data.goods[0])
										storecart({
											storeId: headtals.id,
											goods: cartDetails.list2
										}).then(res => {
											if (res.code == 200) {
												cardetaslist()
											} else {
												uni.showToast({
													icon: 'none',
													title: res.msg
												})
											}
										})
										return;
									} else if (cartDetails.list2[i].id == goodsInfo.id && !isEqualArray(
											cartDetails.list2[i].batchingIds, batchingId.value) && i ==
										cartDetails.list2.length - 1) {
										cartDetails.list2.push(data.goods[0])
										storecart({
											storeId: headtals.id,
											goods: cartDetails.list2
										}).then(res => {
											if (res.code == 200) {
												cardetaslist()
											} else {
												uni.showToast({
													icon: 'none',
													title: res.msg
												})
											}
										})
										return;
									}

								}
							} else if (goodsInfo.specType == 1 && filteredArr.length > 0) {
								for (let i = 0; i < cartDetails.list2.length; i++) {
									if (cartDetails.list2[i].batchingIds == null && batchingId.value.length ==
										0 && cartDetails.list2[i].id == goodsInfo.id) {
										cartDetails.list2[i].num = data.goods[0].num
										storecart({
											storeId: headtals.id,
											goods: cartDetails.list2,
										}).then(res => {
											if (res.code == 200) {
												cardetaslist()
											}
										})
										return;
									} else if (isEqualArray(cartDetails.list2[i].batchingIds, batchingId
											.value) && cartDetails.list2[i].id == goodsInfo.id) {
										cartDetails.list2[i].num = data.goods[0].num
										storecart({
											storeId: headtals.id,
											goods: cartDetails.list2,
										}).then(res => {
											if (res.code == 200) {
												cardetaslist()
											}
										})
										return;
									} else if (cartDetails.list2[i].id == goodsInfo.id && !isEqualArray(
											cartDetails.list2[i].batchingIds, batchingId.value) && i ==
										cartDetails.list2.length - 1) {
										cartDetails.list2.push(data.goods[0])
										storecart({
											storeId: headtals.id,
											goods: cartDetails.list2
										}).then(res => {
											if (res.code == 200) {
												cardetaslist()
											} else {
												uni.showToast({
													icon: 'none',
													title: res.msg
												})
											}
										})
										return;
									}

								}
							} else {
								cartDetails.list2.push(data.goods[0])
								storecart({
									storeId: headtals.id,
									goods: cartDetails.list2
								}).then(res => {
									if (res.code == 200) {
										cardetaslist()
									} else {
										uni.showToast({
											icon: 'none',
											title: res.msg
										})
									}
								})
							}

							return
					}




				}
			})
		}

	}
</script>

<style lang="scss" scoped>
	.contentbox {
		width: 100%;
		height: 100vh;
	}

	.addcar {
		width: 44rpx;
		height: 44rpx;
		background-color: #FE861C;
		border-radius: 50%;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.addcarsa {
		background-color: #FE861C;
		padding: 6rpx 10rpx;
		font-size: 24rpx;
		color: #fff;
		border-radius: 8rpx;
	}

	.jaddcar {
		width: 42rpx;
		height: 42rpx;
		background-color: #fff;
		border: 1px solid #FE861C;
		border-radius: 50%;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.numbershop {
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #000000;
		padding: 0 20rpx;
	}

	.salesNum {
		display: flex;
		justify-content: space-between;
		margin-top: 25rpx;
	}

	.mounys {
		display: flex;
		justify-content: space-between;
		width: 100%;
		margin-top: 10rpx;
	}

	.nummoyneys {
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #FB2A2A;
	}

	.nummoyneysasd {
		color: #FB2A2A;
		font-weight: bold;
	}

	.detalcontent {
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #010101;
		word-wrap: break-word;
	}

	.detalstitle {
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #000000;
	}

	.btnBox {
		width: 186rpx;
		height: 58rpx;
		background: #FE861C;
		border-radius: 10rpx;
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
	}

	.title {
		font-size: 40rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #000000;
		margin-top: 30rpx;
	}

	.centerheight {
		display: flex;
		align-items: center;
	}

	.center {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.oneboder {
		border-bottom: 1px solid #efefef;
		transform: scaleY(.5);
	}

	.boderbottom {
		width: 100%;
		border-bottom: 1px solid #Efefef;
	}

	.boxbachtactive {
		border: 1px solid #FE861C;
		border-radius: 10rpx;
		margin-top: 10rpx;
		color: #FE861C;
		margin-right: 40rpx;
		background-color: #fff4ea;

		.rightbodr {
			padding: 5rpx 14rpx;
			font-size: 28rpx;
			// white-space: nowrap;
			border-right: 1px solid #FE861C;
		}

		.lingsd {
			// white-space: nowrap;
			font-size: 28rpx;
			padding: 5rpx 14rpx;
		}
	}

	.boxbacht {
		border: 1px solid #F0F0F0;
		border-radius: 10rpx;
		margin-top: 10rpx;
		margin-right: 40rpx;

		.rightbodr {
			// white-space: nowrap;
			font-size: 28rpx;
			padding: 5rpx 14rpx;
			border-right: 1px solid #F0F0F0;
		}

		.lingsd {
			// white-space: nowrap;
			font-size: 28rpx;
			padding: 5rpx 14rpx;
		}
	}

	.button {
		position: fixed;
		width: calc(100% - 40rpx);
		bottom: 40rpx;
		left: 20rpx;
		z-index: 555;
		height: 98rpx;
		background: #383838;
		border-radius: 49rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.smallbuton {
			margin-right: 20rpx;
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			background-color: #555555;
			padding: 16rpx 30rpx;
			text-align: center;
			border-radius: 36rpx;

		}

		.smallbuton2 {
			margin-right: 20rpx;
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			background-color: #FE861C;
			padding: 16rpx 30rpx;
			text-align: center;
			border-radius: 36rpx;

		}

		.btinone {
			display: flex;
			align-items: center;
		}

		.imghui {
			width: 88rpx;
			height: 66rpx;
		}

		.money {
			padding-left: 24rpx;
			font-size: 22rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #FFFFFF;

			.nummoney {
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 500;
			}
		}
	}

	.indicator {
		@include flex(row);
		justify-content: center;

		&__dot {
			height: 6px;
			width: 6px;
			border-radius: 100px;
			background-color: rgba(255, 255, 255, 0.35);
			margin: 0 5px;
			transition: background-color 0.3s;

			&--active {
				background-color: #ffffff;
			}
		}
	}

	.indicator-num {
		padding: 2px 0;
		background-color: rgba(0, 0, 0, 0.35);
		border-radius: 100px;
		width: 35px;
		@include flex;
		justify-content: center;

		&__text {
			color: #FFFFFF;
			font-size: 12px;
		}
	}

	// ::v-deep(.u-swiper__indicator .data-v-4e7d0c90) {
	// 	right: 40rpx !important;
	// 	bottom: 40rpx !important;
	// }
	.btinone {
		padding-left: 40rpx;
	}

	::v-deep .u-badge--error.data-v-06cca9b7 {
		background-color: #F12A2A;
	}

	.addcarsa {
		background-color: #FE861C;
		padding: 6rpx 10rpx;
		font-size: 24rpx;
		color: #fff;
		border-radius: 8rpx;
	}

	.addcarsa {
		background-color: #FE861C;
		padding: 6rpx 10rpx;
		font-size: 24rpx;
		color: #fff;
		border-radius: 8rpx;
	}

	.addcarsas {
		background-color: #ffffff;
		padding: 6rpx 10rpx;
		font-size: 24rpx;
		color: #fff;
		border-radius: 8rpx;
	}

	.minus {
		width: 22px;
		height: 22px;
		border-width: 1px;
		border-color: #FE861C;
		border-top-left-radius: 100px;
		border-top-right-radius: 100px;
		border-bottom-left-radius: 100px;
		border-bottom-right-radius: 100px;
		@include flex;
		justify-content: center;
		align-items: center;
	}

	.input {
		padding: 0 20rpx;
	}

	.plusss {
		width: 22px;
		height: 22px;
		background-color: #cccccc;
		border-radius: 50%;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		justify-content: center;
		align-items: center;
	}

	.plus {
		width: 22px;
		height: 22px;
		background-color: #FE861C;
		border-radius: 50%;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		justify-content: center;
		align-items: center;
	}
</style>
<style>
	::v-deep(.u-swiper__indicator) {
		right: 30rpx !important;
		bottom: 40rpx !important;
	}

	.popupShow {
		height: 100vh;
	}
</style>